/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cbsrs.view;

import com.cbsrs.controller.CollegeDAO;
import com.cbsrs.controller.ProgramRevisionDAO;
import com.cbsrs.controller.StudentDAO;
import com.cbsrs.model.Colleges;
import com.cbsrs.model.ProgramRevisions;
import com.cbsrs.model.Student;
import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import org.apache.log4j.Logger;

/**
 *
 * @author Arnold
 */
public class UserAction extends ActionSupport {

    private String actionMessage;
    private int result;
    private Student users;
    public String studentID, studentIDno, studentPassword, studentEmail, collegeID, programRevisionID, studentFirstName, studentMiddleName, studentLastName, studentAddress, studentDateOfBirth, studentPlaceOfBirth, studentContactNo, studentYear;
    List<Colleges> collegeList = new ArrayList<Colleges>();
    List<ProgramRevisions> programRevisionList = new ArrayList<ProgramRevisions>();
    List<Student> studentList = new ArrayList<Student>();
    ProgramRevisions programRevisions;
    Colleges colleges;
    Student student;
    private static final Logger log = Logger.getLogger(UserAction.class);

    public String viewCollegePrograms() {
        try {
            log.info("College ID :"+ collegeID);
            collegeList = CollegeDAO.findAll();
            log.info("List SIZE :" + collegeList.size());
            colleges = collegeList.get(0);
            if (!collegeID.isEmpty()) {
                programRevisionList = ProgramRevisionDAO.findAll(Integer.parseInt(collegeID));
                log.info("Program Revision List Size:" + programRevisionList.size());
            }

        } catch (Exception ex) {
            log.error(ex);
        }
        return SUCCESS;
    }

    public String registerUser() {
        if (studentPassword != null && studentEmail != null && studentFirstName != null
                && studentLastName != null) {
            String studentIDNumber=StudentDAO.register(studentPassword, studentEmail,
                    Integer.parseInt(collegeID), Integer.parseInt(programRevisionID),
                    studentFirstName, studentMiddleName, studentLastName, studentDateOfBirth, studentPlaceOfBirth,
                    studentContactNo, studentAddress);
            if (!studentIDNumber.isEmpty()) {
                studentIDno=studentIDNumber;
                log.info("Successfully saved user");
                addActionMessage("Successfully saved student. Please take note of the your ID Number.");
            }else{
                log.info("Unable to save student");
                addActionError("Unable to save student.");
            }
        }

        return SUCCESS;
    }

    public String getStudentID() {
        return studentID;
    }

    public void setStudentID(String studentID) {
        this.studentID = studentID;
    }

    public String getActionMessage() {
        return actionMessage;
    }

    public void setActionMessage(String actionMessage) {
        this.actionMessage = actionMessage;
    }

    public String getCollegeID() {
        return collegeID;
    }

    public void setCollegeID(String collegeID) {
        this.collegeID = collegeID;
    }

    public String getProgramRevisionID() {
        return programRevisionID;
    }

    public void setProgramRevisionID(String programRevisionID) {
        this.programRevisionID = programRevisionID;
    }

    public int getResult() {
        return result;
    }

    public void setResult(int result) {
        this.result = result;
    }

    public String getStudentAddress() {
        return studentAddress;
    }

    public void setStudentAddress(String studentAddress) {
        this.studentAddress = studentAddress;
    }

    public String getStudentContactNo() {
        return studentContactNo;
    }

    public void setStudentContactNo(String studentContactNo) {
        this.studentContactNo = studentContactNo;
    }

    public String getStudentDateOfBirth() {
        return studentDateOfBirth;
    }

    public void setStudentDateOfBirth(String studentDateOfBirth) {
        this.studentDateOfBirth = studentDateOfBirth;
    }

    public String getStudentEmail() {
        return studentEmail;
    }

    public void setStudentEmail(String studentEmail) {
        this.studentEmail = studentEmail;
    }

    public String getStudentFirstName() {
        return studentFirstName;
    }

    public void setStudentFirstName(String studentFirstName) {
        this.studentFirstName = studentFirstName;
    }

    public String getStudentIDno() {
        return studentIDno;
    }

    public void setStudentIDno(String studentIDno) {
        this.studentIDno = studentIDno;
    }

    public String getStudentLastName() {
        return studentLastName;
    }

    public void setStudentLastName(String studentLastName) {
        this.studentLastName = studentLastName;
    }

    public String getStudentMiddleName() {
        return studentMiddleName;
    }

    public void setStudentMiddleName(String studentMiddleName) {
        this.studentMiddleName = studentMiddleName;
    }

    public String getStudentPassword() {
        return studentPassword;
    }

    public void setStudentPassword(String studentPassword) {
        this.studentPassword = studentPassword;
    }

    public String getStudentPlaceOfBirth() {
        return studentPlaceOfBirth;
    }

    public void setStudentPlaceOfBirth(String studentPlaceOfBirth) {
        this.studentPlaceOfBirth = studentPlaceOfBirth;
    }

    public String getStudentYear() {
        return studentYear;
    }

    public void setStudentYear(String studentYear) {
        this.studentYear = studentYear;
    }

    public Student getUsers() {
        return users;
    }

    public void setUsers(Student users) {
        this.users = users;
    }

    public List<Colleges> getCollegeList() {
        return collegeList;
    }

    public void setCollegeList(List<Colleges> collegeList) {
        this.collegeList = collegeList;
    }

    public List<ProgramRevisions> getProgramRevisionList() {
        return programRevisionList;
    }

    public void setProgramRevisionList(List<ProgramRevisions> programRevisionList) {
        this.programRevisionList = programRevisionList;
    }

    public ProgramRevisions getProgramRevisions() {
        return programRevisions;
    }

    public void setProgramRevisions(ProgramRevisions programRevisions) {
        this.programRevisions = programRevisions;
    }

    public Colleges getColleges() {
        return colleges;
    }

    public void setColleges(Colleges colleges) {
        this.colleges = colleges;
    }

    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    public List<Student> getStudentList() {
        return studentList;
    }

    public void setStudentList(List<Student> studentList) {
        this.studentList = studentList;
    }
    
}
